﻿using ApiLib.AppStart;
using SqlSugar;

namespace ApiLib.Cloud.Models;

/// <summary>
/// 网关路由配置
///</summary>
[Tenant(GlobalConstants.MainDbConfigId), SugarTable("sys_cloud_route")]
public class SysCloudRoute
{
    /// <summary>
    ///  
    ///</summary>
    [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
    public int Id { get; set; }

    /// <summary>
    /// 地址/开始 
    ///</summary>
    [SugarColumn(ColumnName = "path")]
    public string Path { get; set; }

    /// <summary>
    /// 类型：0白名单，1，需要认证，2黑名单 
    /// 默认值: 0
    ///</summary>
    [SugarColumn(ColumnName = "type")]
    public CloudRouteType Type { get; set; }

    /// <summary>
    /// 是否禁用 
    /// 默认值: 0
    ///</summary>
    [SugarColumn(ColumnName = "forbidden")]
    public bool Forbidden { get; set; }

    /// <summary>
    /// 创建人 
    ///</summary>
    [SugarColumn(ColumnName = "add_user")]
    public string AddUser { get; set; }

    /// <summary>
    /// 创建时间 
    ///</summary>
    [SugarColumn(ColumnName = "add_time")]
    public DateTime? AddTime { get; set; }

    /// <summary>
    /// 是否白名单
    /// </summary>
    [SugarColumn(IsIgnore = true)]
    public bool IsWhite => Type == CloudRouteType.White;
    
    /// <summary>
    /// 是否黑名单
    /// </summary>
    [SugarColumn(IsIgnore = true)]
    public bool IsBlack => Type == CloudRouteType.Black;
}

/// <summary>
/// 路由类型
/// </summary>
public enum CloudRouteType
{
    /// <summary>
    /// 白名单
    /// </summary>
    White=0,
    /// <summary>
    /// 需要认证
    /// </summary>
    Auth=1,
    /// <summary>
    /// 黑名单
    /// </summary>
    Black=2
}